5 Replies - 4268 Views - Last Post: 25 March 2009 - 11:39 AM Rate Topic: -----

#1 HATE U JAVA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 09

simple textual Tic-Tac-Toe game

Post icon  Posted 23 February 2009 - 09:22 AM

package Program3;
import java.util.Scanner;
public class program3 {
public static void main (String [] args)
{
	
	Scanner Scan = new Scanner (System.in);
	
			String ch1 =  "1";
			String ch2 =  "2";
			String ch3 =  "3";
			String ch4 =  "4";
			String ch5 =  "5";
			String ch6 =  "6";
			String ch7 =  "7";
			String ch8 =  "8";
			String ch9 =  "9";
			
			printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
						}
	which(true) 
	{
		While(true);
		{System.out.print("Player 1 please make your move > ");
		String player1 = Scan.next();
		
		Scanner p1 = new Scanner (player1);
		if (p1.hasnextInt())
		{int playmore =p1.nextInt();}
	
		switch(playmore)
			{
			case 1:
					ch1=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 2:
					ch2=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 3:
					ch3=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 4:
					ch4=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 5:
					ch5=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 6:
					ch6=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 7:
					ch7=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 8:
					ch8=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
			case 9:
					ch9=p1;
					printGrid(ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9);
					break;
	
					
					
			}
			
		else
		{System.out.print("you have input invalid data please enter an integer");}
		continue; 
		
		
		
		 break;}
	}
		public static void printGrid( String a, String b, String c, String d, String e, String f, String g, String h , String i )
		{
			System.out.println(a+" / "+b+" / "+c);
			System.out.println( "-----");
			System.out.println( d+" / "+e+" / "+f);
			System.out.println( "-----");
			System.out.println( g+" / "+h+" / "+i);
			}
		
		
}


Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: simple textual Tic-Tac-Toe game

#2 Lucrosen  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 21
  • Joined: 11-February 09

Re: simple textual Tic-Tac-Toe game

Posted 23 February 2009 - 09:31 AM

What problems are you having?
Was This Post Helpful? 0
  • +
  • -

#3 HATE U JAVA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 09

Re: simple textual Tic-Tac-Toe game

Posted 23 February 2009 - 10:23 AM

I want A Tic Tac toe game I have to ask palyer1 to enter en integer and make a move and it must be from 1 to 9, and ask player2 the same thing and I must check if there is a winner after each move.

This post has been edited by HATE U JAVA: 23 February 2009 - 10:30 AM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: simple textual Tic-Tac-Toe game

Posted 24 February 2009 - 09:28 PM

You are in a Java lovers forum... don't think your nickname incite us to help you :D

Anyhow

   which(true) 
	{
		While(true);



which is not a valid Java statement hate it or not :)

While(true)... you probably mean while(true) .... Java is case sensitive hate it or not

your while statement ends up with a ; so it will while() forever the syntax is

[code]
while(true) {
.... while body
}
/code]
Was This Post Helpful? 0
  • +
  • -

#5 HATE U JAVA  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-February 09

Re: simple textual Tic-Tac-Toe game

Posted 25 March 2009 - 11:31 AM

Hi please I need to know how to change my name :( But I dont know how ??
Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,595
  • Joined: 16-October 07

Re: simple textual Tic-Tac-Toe game

Posted 25 March 2009 - 11:39 AM

You want to use an array. Chances are you just covered arrays, or even 2D arrays, in class and this is the thing to test your understanding.

Change name? The site admins might slap me for this, but... You've only posted three times. Make a new account with a less provocative name, one you like, and never use this one again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1