Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions TicTacToe-Java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.
Binary file not shown.
Binary file not shown.
71 changes: 71 additions & 0 deletions src/local/jlw23339/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package local.jlw23339;

import java.util.Scanner;

public class Main
{

public static void main(String[] args)
{
// write your code here
char[][] board = {{' ',' ', '|', ' ',' ', '|',' ', ' '},
{'-','-', '+', '-','-', '+', '-','-'},
{' ',' ', '|', ' ',' ', '|',' ', ' '},
{'-','-', '+', '-','-', '+', '-','-'},
{' ',' ', '|', ' ',' ', '|',' ', ' '}};

Player p1 = new Player();
Player p2 = new Player();
System.out.println(p1.getPlayer());
System.out.println(p2.getPlayer());
printboard(board);
Scanner s = new Scanner(System.in);
System.out.println("Choose a position: ");
int position = s.nextInt();
chooseposition(position, board);
printboard(board);

}
public static void printboard(char[][] board){
for(char[] row : board)
{
for (char ch : row)
{
System.out.print(ch);
}
System.out.println();
}
}
public static void chooseposition(int position, char[][] board/**, User user**/){
switch(position){
case 1:
board[0][0] = 'X';
break;
case 2:
board[0][3] = 'X';
break;
case 3:
board[0][6] = 'X';
break;
case 4:
board[2][0] = 'X';
break;
case 5:
board[2][3] = 'X';
break;
case 6:
board[2][6] = 'X';
break;
case 7:
board[4][0] = 'X';
break;
case 8:
board[4][3] = 'X';
break;
case 9:
board[4][6] = 'X';
break;

}
}
}
42 changes: 42 additions & 0 deletions src/local/jlw23339/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package local.jlw23339;

import java.util.Scanner;

public class Player
{
private static int maxid;
public int id;
public String name;
public char symbol;

public Player()
{
maxid++;
this.id = maxid;
Scanner s = new Scanner(System.in);
System.out.println("Enter a Name for player " + maxid+": ");
String res = s.next();
if( this.id == 1){
this.symbol = 'X';
}else{
this.symbol = 'O';
}
this.name = res;
}

public String getPlayer()
{
return "Player"+this.id;
}

public String getName()
{
return name;
}

public char getSymbol()
{

return symbol;
}
}